<?php

class User extends AppModel
{
    var $name = 'User';
    var $hasOne = array('Profile' => array('className' => 'Profile', 'foreignKey' =>
                'user_id'));
    var $hasMany = array('FriendUser'=>array('className'=>'FriendUser','foreignKey'=>'user_id',
                                              'conditions'=>array('FriendUser.user_id'=>'User.id'))
                          );
    var $validate = array(
        'username' => array('username_must_not_be_blank' => array('rule' => 'notEmpty',
                    'message' => 'Vui long nhap thong tin'), 'username_must_be_unique' => array('rule' =>
                    'isUnique', 'message' => 'Tai khoan da bi trung')),
        'password' => array('password_must_not_be_blank' => array('rule' => 'notEmpty',
                    'message' => 'Vui long nhap thong tin')),
        'repassword' => array('repassword_must_not_be_blank' => array('rule' => 'notEmpty',
                    'message' => 'Vui long nhap thong tin')),
        'email' => array('email_must_not_be_blank' => array('rule' => 'notEmpty',
                    'message' => 'Vui long nhap thong tin'),'email_must_be_unique' => array('rule' =>
                    'isUnique', 'message' => 'Email da được sử dụng')));
    function beforeSave($options = array())
    {
        Security::setHash('md5');
        if ($this->data['User']['password']&&$this->data['User']['repassword'])
        {
            $this->data['User']['password'] = md5($this->data['User']['password']);
            $this->data['User']['repassword'] = md5($this->data['User']['repassword']);
        }
        return true;
    }
}
